package leetcode;

//删除排序链表中的重复项
public class DeleteDuplicates {
    public ListNode deleteDuplicates(ListNode head) {
        if (head==null || head.next==null) return head;
        ListNode listNode = new ListNode(Integer.MAX_VALUE);
        listNode.next = head;
        ListNode pre =listNode;
        ListNode right = listNode.next;
        while (right!=null && right.next!=null){
            if (right.next.val == right.val){
                int value = right.val;
                while (right!=null && right.val == value){
                    right = right.next;
                }
                pre.next = right;
            }else {
                pre = pre.next;
                right = right.next;
            }
        }
        return listNode.next;
    }

    public class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }
}
